import Entity from './entity'
import { LogTypes, LogStatus } from '../common/enums'

export default class LogParent extends Entity {
    constructor(db, collectionName) {
        super(db, collectionName)
    }

    async statLogBySuite() {
        const stepLogsCountMap = await this.groupBy({ type: LogTypes.step, status: { $in: [LogStatus.pass, LogStatus.failure] } }, '$suiteId')
        return stepLogsCountMap
    }

    async statLogByPlan() {
        const stepLogsCountMap = await this.groupBy({ type: LogTypes.step, status: { $in: [LogStatus.pass, LogStatus.failure] } }, '$planId')
        return stepLogsCountMap
    }

    async addLog([type, data]) {
        await this.insert({ type, ...data })
    }
}